//
//  NewsController.m
//  AntsExpress
//
//  Created by slccper on 16/1/11.
//  Copyright © 2016年 slccper. All rights reserved.
//

#import "NewsController.h"
#import "NewsViewCell.h"
#import "NewDetailController.h"
@interface NewsController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSMutableArray *dataList;
}
@property (weak, nonatomic) IBOutlet UIView *headerview;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation NewsController

- (void)viewDidLoad {
    [super viewDidLoad];
    dataList = [NSMutableArray array];
    self.tableView.rowHeight=30;
//    self.tableView.sectionHeaderHeight=40;
    self.tableView.tableFooterView=[[UIView alloc]init];
    self.title=@"螞蟻公告";
    // Do any additional setup after loading the view from its nib.
}
-(void)getWebData
{
    if ([clsOtherFun CheckNetworkStatus:YES]) {
        [clsOtherFun showLoadingView:@"正在獲取數據..."];
        ants = [[clsAntsService alloc]init];
        ants.delegate=self;
        [ants GetHotNews];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"NewsViewCell";
    
    NewsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"NewsViewCell" owner:self options:nil]lastObject];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSDictionary *dic = [dataList objectAtIndex:indexPath.row];
    [cell setDataByDic:dic];
//    clscalcula *calcula = [dataList objectAtIndex:indexPath.section];
//    //    cell.imageView.image=[clsOtherFun createImageWithColor:[UIColor blueColor]];
//    [cell.addTitle setTitle:calcula.AreaName forState:UIControlStateNormal];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = [dataList objectAtIndex:indexPath.row];
    NewDetailController *detail = [[NewDetailController alloc]initWithNibName:@"NewDetailController" bundle:nil];
    detail.isBack = YES;
    detail.dic = dic;
    [self.navigationController pushViewController:detail animated:YES];
}
//-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    return self.headerview;
//}

-(void)getAntsDataSuccess:(NSInteger)type :(NSMutableDictionary *)pDictionary
{
    [clsOtherFun hideLoadingView];
    NSDictionary *dic = [pDictionary objectForKey:@"data"];
    dataList = [dic objectForKey:@"data"];
    [self.tableView reloadData];
}
@end
